<?php

namespace App\Api\V1\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Feedback;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redis;

class FeedbackController extends Controller
{
    protected $guard = 'api';

    /**
     * 添加反馈
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addFeedback(Request $request)
    {
        $this->validate($request, [
            'contents' => 'required'
        ]);

        $user = Auth::guard($this->guard)->user();

        $feedback = new Feedback();
        $feedback->user_id = $user['id'];
        $feedback->contents = $request->contents;

        $flag = $feedback->save();

        if ($flag)
            return response()->json([
                'status_code' => 1,
                'message'     => '添加成功'
            ]);
        else
            return response()->json([
                'status_code' => 0,
                'message'     => '添加失败'
            ]);
    }

}
